
var bsurl = require('baseUrl.js');
var app = getApp();
module.exports = {
  sendRequest: sendRequest
}

function sendRequest(url, _data, successFunc) {
  wx.showToast({
    title: '加载中...',
    icon: "loading",
    duration: 250000
  });
  var that = this;
  wx.request({
    url: bsurl + url,
    method: "post",
    data: {
      body: _data
    },
    header: {
      'content-type': 'application/json', // 默认值
      JSESSIONID: app.globalData.JSESSIONID
    },
    success: function (res) {
      wx.hideToast();
      if (res.statusCode != 200) {
        wx.showModal({
          title: '提示',
          content: "请求失败",
        });
        return;
      }
      console.log(res);
      if (res.data.success) {
        if (successFunc)
          successFunc(res.data);
      }
      else {
        wx.showModal({
          title: '提示',
          content: res.data.message,
        });
      }
    },
    fail: function (res) {
      wx.hideToast();
      wx.showModal({
        title: '提示',
        content: "网络请求失败",
      });
    }
  });
  return;
}